package com.teach.controller.shop;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mysql.cj.Session;
import com.teach.dto.LoginUser;
import com.teach.service.UserService;
import com.teach.service.shop.ShopGoodsCartService;

import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
public class ShopCartController {
	
	@GetMapping("/index.cart")
	public String doHotel() {
		return "shop/cart";
	}	
	@Autowired
	private  ShopGoodsCartService service;

	@RequestMapping("/cart.do")
	public String name(Model model,LoginUser username) {
		model.addAttribute("list", service.selectShopCart(username.getUserName()));
		log.debug("{}",service.get(username.getUserName()));
		return "/shop/cart";
	}
	@RequestMapping("/carts.do")
	public String dodelect(@RequestParam(value = "goodsname")Long goodsname,LoginUser username) {
		service.deleteCart(goodsname, username.getUserName());
		return "redirect:/cart.do";
	}
	
}
